package com.atguigu.gmall.order.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.UserAuthUtil;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.order.vo.OrderConfirmDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lfy
 * @Description
 * @create 2023-08-01 14:35
 */
@RequestMapping("/api/inner/order")
@RestController
public class OrderRpcController {


    @Autowired
    OrderBizService orderBizService;

    @Autowired
    OrderInfoService orderInfoService;

    /**
     * 按照订单id查询订单数据
     * @param orderId
     * @return
     */
    @GetMapping("/info/{orderId}")
    public Result<OrderInfo> getOrderInfoById(@PathVariable("orderId") Long orderId){

        String userid = UserAuthUtil.getUserAuth().getUserid();

        OrderInfo info = orderInfoService.lambdaQuery()
                .eq(OrderInfo::getId, orderId)
                .eq(OrderInfo::getUserId, Long.parseLong(userid))
                .one();

        return Result.ok(info);
    }


    /**
     * 返回订单确认页数据
     * @return
     */
    @GetMapping("/confirm/data")
    public Result<OrderConfirmDataVo> confirmDataVoResult(){

        OrderConfirmDataVo vo = orderBizService.getConfirmData();

        return Result.ok(vo);
    }
}
